package hmis.pos.Service.ServiceImpl;

import hmis.pos.Base.BaseService.Impl.BaseServiceImpl;
import hmis.pos.Repository.RoomMessageRepository;
import hmis.pos.Repository.RoomTypeRepository;
import hmis.pos.Entity.RoomType;
import hmis.pos.Service.RoomTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class RoomTypeServiceImpl extends BaseServiceImpl<RoomType,RoomTypeRepository> implements RoomTypeService {

    @Autowired
    private RoomTypeRepository roomTypeRepository;

    @Autowired
    private RoomMessageRepository roomMessageRepository;

    @Override
    public RoomType findByType(String type) {
        return roomTypeRepository.findByType(type);
    }

    @Override
    public RoomType save(RoomType roomType){
        if(roomTypeRepository.findByType(roomType.getType())!=null)
            return null;
        return roomTypeRepository.save(roomType);
    }

    @Override
    public boolean delete(RoomType roomType){
        if(roomTypeRepository.findById(roomType.getId())==null){
            return false;
        }

        if(roomMessageRepository.findByType(roomType.getType()).size()!=0){
            return false;
        }

        roomTypeRepository.delete(roomType);
        return true;
    }

}
